package com.lwc.cfdns.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwc.cfdns.pojo.entity.SystemRoleDept;
import com.lwc.cfdns.pojo.entity.SystemRoleMenu;
import com.lwc.cfdns.service.SystemRoleDeptService;
import com.lwc.cfdns.mapper.SystemRoleDeptMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author spring
 * @description 针对表【cfdns_system_role_dept(角色和部门(数据权限)关联表(角色1-N部门))】的数据库操作Service实现
 * @createDate 2023-05-30 10:00:59
 */
@Service
public class SystemRoleDeptServiceImpl extends ServiceImpl<SystemRoleDeptMapper, SystemRoleDept>
        implements SystemRoleDeptService {

    /**
     * 角色数据权限
     * 角色与部门关联表
     *
     * @param deptIds
     * @param roleId
     * @return Boolean
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/30 10:34:52
     */
    public Boolean deptIds(List<Long> deptIds, Long roleId) {
        // 删除原来的权限
        this.baseMapper.delete(new LambdaQueryWrapper<SystemRoleDept>().eq(SystemRoleDept::getRoleId, roleId));
        if (deptIds.size() > 0) {
            ArrayList<SystemRoleDept> listDepts = new ArrayList<>();
            for (Long deptId : deptIds) {
                SystemRoleDept systemRoleDept = new SystemRoleDept();
                systemRoleDept.setDeptId(deptId);
                systemRoleDept.setRoleId(roleId);
                listDepts.add(systemRoleDept);
            }
            // 批理插入
            this.saveBatch(listDepts);
        }
        return true;
    }
}




